#!/bin/bash

sudo stars start;
sleep 3;
sudo stars status;


echo "check remote_tunnel......"

check_tunnel1=`ssh -p 33 root@192.168.188.1 "echo 'pass...'"||echo 'failed'`

if [[ "${check_tunnel1}" =~ "pass" ]];then
        tunnel='root@192.168.188.1 -p 33'
elif [[ "${check_tunnel1}" =~ "failed" ]];then
         check_tunnel2=`ssh super@192.168.188.4 "echo 'pass...'"||echo 'failed'`
         if [[ "${check_tunnel2}" =~ "pass" ]];then

                tunnel='super@192.168.188.4'
         else
                echo "no tunnel found!"
                exit 1
         fi
fi


echo "start proxy in 0.0.0.0:22007......"
ps -ef|grep '0.0.0.0:22007'|grep -v grep|awk '{print$2}'|xargs kill -9 >/dev/null 2>&1;
autossh  -M 5678 -f -N -D  0.0.0.0:22007  ${tunnel}



#  wget  --no-check-certificate http://gitee.com/team_space/mynet_info/raw/master/StarVpn.sh -O StarVpn.sh&& bash StarVpn.sh